package se.kth.fericss.rts;

import java.awt.Dimension;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import se.kth.fericss.obj.ControllableObject;
import se.kth.fericss.obj.GameObject;
import se.kth.fericss.util.Timer;

/**
 * Displays the game's GUI and handles mouse clicks on it.
 */
public class Gui {
	private World world;
	private String statusText = "";
	private Timer statusTextTimer;
	private Dimension screenSize;

	public Gui(World world, Dimension screenSize) {
		this.world = world;
		this.screenSize = screenSize;
		statusTextTimer = Timer.createTimer(3000);
	}

	public void draw(Graphics g) {
		drawMainGui(g);

		if(!statusTextTimer.isDone()) {
			g.setColor(Color.white);
			g.drawString(statusText, screenSize.width-200, screenSize.height - 25);
		}

		//Draw text at the top of the screen
		g.setColor(Color.white);
		//String unitCount = "Objects: " + world.getAllUnits().size();
		//String collisionChecks = String.format("Collision checks: %1$,d", GameObject.getCollisionChecks());
		//g.drawString(collisionChecks + " " + unitCount, 100, 10);
		//g.drawString("Frame count: " + (frameCount + 1) + " Update count: " + updateCount, 60, 25);
		//g.drawString(worldView.getCurrentViewLocation().toString(), 500, 10);
	}

	/**
	 * Draw the GUI at the bottom of the screen.
	 */
	private void drawMainGui(Graphics g) {
		//Draw background rectangle
		g.setColor(Color.lightGray);
		g.fillRect(0, screenSize.height - 150, screenSize.width, 150);

		//Draw selected units info
		g.setColor(Color.white);
		int count = 0;
		//for(ControllableObject object : world.getObjects(ControllableObject.class)) {
		//	if(object.isSelected()) {
		//		count++;
		//		
		//		if(object.getBehavior() != null) {
		//			g.drawString(object.getBehavior().toString(), 0, screenSize.height - 110);
		//		}
		//	}
		//}

		g.drawString("Selected objects: " + count, screenSize.width-200, screenSize.height - 130);
	}

	/**
	 * Sets the status text shown at the bottom of the screen.
	 */
	public void setStatusText(String statusText) {
		this.statusText = statusText;
		statusTextTimer.reset();
	}
}
